#pragma once
#include <SFML/Graphics/Drawable.hpp>
#include <nice2d/component.h>
#include <nice2d/widgets/control.h>
#include <nice2d/widgets/dock.h>

class Desktop final:
    public Component,
    public MessageReceiver,
    public sf::Drawable,
    public std::enable_shared_from_this<Desktop>
{
public:
    Desktop();
    ~Desktop();
public:
    std::shared_ptr<Dock> addWidget(ControlPointer control);
    void removeWidget(ControlPointer widget);
    void clearAllWidgets();
public:
    ControlPointer getFocusWidget()const;
    void setFocusWidget(ControlPointer widget);

    ControlPointer getPopupWidget()const;
    void setPopupWidget(ControlPointer widget);

    ControlPointer widgetBelowCursor()const;
    bool isTopWidget(ControlPointer widget)const;

    void setMouseCaptureControl(ControlPointer control);
    void releaseMouseCaptureControl();
    ControlPointer getMouseCaptureControl()const;
public:
    void registerControlStyle(const std::string& control,std::shared_ptr<ControlStyle> style);
    std::list<std::string> getControlStyles()const;
    std::shared_ptr<ControlStyle> getControlStyle(const std::string& control);
public:
    int largestZValue()const;
    void checkForControlBelowCursor();
    bool process(std::shared_ptr<Message> message) override;
    void update(float deltaTime) override;
    void draw(sf::RenderTarget &target, sf::RenderStates states) const override;
private:
    std::unique_ptr<class DesktopData> data;
};
